package com.jctrip.hotel.source.mq;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author: zxy
 * @CreateTime: 2024-01-30 16:11
 * @Description:
 */
@Slf4j
@Component
public class PoiCallbackMQProducer {

    @Resource(name = "poiCallbackDefaultMQProducer")
    private DefaultMQProducer poiCallbackDefaultMQProducer;

    public void send(String msg) {
        Message message = new Message("poiCallbackMeituan", "", msg.getBytes());
        try {
            poiCallbackDefaultMQProducer.send(message, new SendCallback() {
                @Override
                public void onSuccess(SendResult sendResult) {
                }

                @Override
                public void onException(Throwable throwable) {
                    log.error("send log callback error!", throwable);
                }
            });
        } catch (Exception e) {
            log.error("send log error!", e);
        }
    }
}